package com.sky.mapper;


import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
     List<Orders> processTimeoutOrder(Integer status, LocalDateTime orderTime);

    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    /**
     * 用于替换微信支付更新数据库状态的问题
     * @param orderStatus
     * @param orderPaidStatus
     */
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} " +
            "where number = #{orderNumber}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, String orderNumber);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getOrderbyId(Long id);


    /**
     * 根据用户id查询订单
     * @param ordersPageQueryDTO
     * @return
     */

    List<Orders> getOrderbyUserId(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 取消订单
     * @param cancelled
     * @param now
     * @param id
     */
    @Update("update orders set status = #{cancelled},cancel_time = #{now} where id = #{id}")
    void updateStatu(Integer cancelled, LocalDateTime now, Long id);


    @Select("select count(id) from orders where status = #{toBeConfirmed}")
    Integer countstatus(Integer toBeConfirmed);

    /**
     * 统计订单数据
     * @param localDates
     * @param completed
     * @return
     */
    @MapKey("")
    List<Map<String, Object>> getStatistics(List<LocalDate> localDates, Integer completed);

    /**
     * 统计订单数据
     * @param map
     * @return
     */
    Integer getordersStatistics(Map map);


    @MapKey("")
    List<Map<String, Object>> gettop10(LocalDate begin, LocalDate end);

    Double getturnover(Map map);

    Integer countByMap(Map map);
}
